package com.example.activitydatatransfer;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class SecondActivity extends AppCompatActivity implements View.OnClickListener {
    Button btnChange2,btnCancel2;
    EditText editTextName2,editTextScore2,editTextPassed2;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_second);
        btnChange2=(Button) findViewById(R.id.btnChange2);
        btnCancel2=(Button) findViewById(R.id.btnCancel2);
        btnChange2.setOnClickListener(this);
        btnCancel2.setOnClickListener(this);
        editTextName2=(EditText) findViewById(R.id.editTextName2);
        editTextScore2=(EditText) findViewById(R.id.editTextScore2);
        editTextPassed2=(EditText) findViewById(R.id.editTextPassed2);
        //获取MainActivity传递的数据
        Intent intent=getIntent();
        editTextName2.setText(intent.getStringExtra("studentName"));
        editTextScore2.setText(intent.getStringExtra("englishScore"));
        editTextPassed2.setText(intent.getStringExtra("isPassed"));
    }

    @Override
    public void onClick(View view) {
        switch(view.getId()){
            case R.id.btnChange2:
                Intent intent=new Intent();
                intent.putExtra("studentName",editTextName2.getText().toString());
                intent.putExtra("englishScore",editTextScore2.getText().toString());
                intent.putExtra("isPassed",editTextPassed2.getText().toString());
                int resultCode=2;
                setResult(resultCode,intent);
                this.finish();
                break;
            case R.id.btnCancel2:
                this.finish();
                break;
        }
    }
}
